$(function() {
    //分类更多
    sortMoreFun();
    //图片数据懒加载
    lazyCourseImage();
    //侧边栏滚动
    asideScroll();

    initIndexTime();
    //扫一扫
    QRCodeInp();

    function QRCodeInp(){
        var mobilePath = $('#mobilePath').val();
        var articleId = $('#articleId').val();
        link = mobilePath + '/mobile/article/articleInfoById?articleId='+articleId + '&isFromCode';
        var qrcode = $('#QRCodeInp').qrcode({render: "canvas", height: 140, width: 140, correctLevel: 2, text: link}).find('canvas').hide();
        var str = '<img src='+ qrcode[0].toDataURL()+ ' width=140 height=140 style=width:140px;height:140px; />'
        $("#QRCodeInp").attr('data-content', str)
    }

    /**
     * 初始首页显示的时间
     */
    function initIndexTime() {
        var time = new Date().getTime();
        setInterval(function () {
            time = time + 1000;
            var _date = new Date(time),
                yyyy = _date.getFullYear(),
                MM = (_date.getMonth() + 1) > 9 ? (_date.getMonth() + 1) : "0" + (_date.getMonth() + 1),
                dd = _date.getDate() > 9 ? _date.getDate() : "0" + _date.getDate(),
                hh = _date.getHours() > 9 ? _date.getHours() : "0" + _date.getHours(),
                mm = _date.getMinutes() > 9 ? _date.getMinutes() : "0" + _date.getMinutes(),
                ss = _date.getSeconds() > 9 ? _date.getSeconds() : "0" + _date.getSeconds();

             $("#year").find('span').text(yyyy);
             $("#monthDate").text(MM + "/" + dd);
             $("#hourMinutes").text(hh + ":" + mm);
        }, 1000);
    }
})

//侧边栏滚动
function asideScroll(){
    var mlwpH = $(".article-ml-wp").height();
    var winH = window.innerHeight;

    $(window).scroll(function() {

        var wpTop = $(".article-main-l").offset().top;
        var wpScrollTop = wpTop - $(document).scrollTop();

        if(wpScrollTop < 0){
            $(".article-ml-wp").css({
                "position":"fixed",
                "top":"20px"
            })
        }else {
            $(".article-ml-wp").css({
                "position":"relative",
                "top":"0"
            })
        }
    })
}